package com.ma5d.driver.customer.controller;

import com.ma5d.driver.common.result.Result;
import com.ma5d.driver.customer.service.CustomerInfoService;
import com.ma5d.driver.model.form.UpdateWxPhoneForm;
import com.ma5d.driver.model.vo.customer.CustomerLoginVo;
import jakarta.annotation.Resource;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/customer/info")
public class CustomerInfoController {

    @Resource
    private CustomerInfoService customerInfoService;

    @GetMapping("/login/{code}")
    public Result<Long> login(@PathVariable("code") String code) throws WxErrorException {
        return Result.ok(customerInfoService.login(code));
    }

    @GetMapping("/getCustomerLoginInfo/{customerId}")
    public Result<CustomerLoginVo> getCustomerLoginInfo(@PathVariable("customerId") Long customerId) {
        CustomerLoginVo customerLoginVo = customerInfoService.getCustomerInfo(customerId);
        // TODO 检查是否会为null
        return Result.ok(customerLoginVo);
    }

    @PostMapping("/updateWxPhoneNumber")
    public Result<Boolean> updateWxPhoneNumber(@RequestBody UpdateWxPhoneForm updateWxPhoneForm){
        return Result.ok(customerInfoService.updateWxPhoneNumber(updateWxPhoneForm));
    }

}
